package com.project.personnel.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.personnel.dao.AdjustsalaryMapper;
import com.project.personnel.dao.EmployeesalaryMapper;
import com.project.personnel.entity.Adjustsalary;
import com.project.personnel.entity.Employeesalary;
import com.project.personnel.entity.Empsalary;
import com.project.personnel.service.AdjustsalaryService;
import com.project.personnel.service.EmployeesalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author diaominyh
 * @since 2022-12-12
 */
@RestController
@RequestMapping("/adjustsalary")
public class AdjustsalaryController {
    @Autowired
    @Resource
    AdjustsalaryService adjustsalaryService;
    @Resource
    AdjustsalaryMapper adjustsalaryMapper;
    @Resource
    EmployeesalaryService employeesalaryService;
    @Resource
    EmployeesalaryMapper employeesalaryMapper;
    /**
     * 查询所有的薪资调整情况 postman测试完成
     * @param id
     * @return
     */
    @RequestMapping("/getAll")
    public List<Adjustsalary> getAll(Integer id){
        return adjustsalaryService.list();
    }
    /**
     * 根据eid去查询该员工是否有薪资调整 postman测试完成
     * @param id
     * @return
     */
    @GetMapping("/getAdjustsalaryUserById/{id}")
    public Adjustsalary getAdjustsalaryUserById(@PathVariable Integer id){
        return adjustsalaryMapper.selectById(id);
    }

    /**
     * 根据id删除薪资调整信息 postman测试完成
     * @param eid
     * @return
     */
    @GetMapping("/getAdjustsalaryUserDel/{eid}")
    public boolean getAdjustsalaryUserDel(@PathVariable Integer eid,Adjustsalary adjustsalary){
        List<Adjustsalary> adjustsalaries = new ArrayList<>();
        adjustsalary = adjustsalaryService.getAdjustsalaryUserDelSel(eid);
        int eid1= adjustsalary.getEid();
        int beforeSalary1= adjustsalary.getBeforeSalary();
        boolean upd = employeesalaryService.getemployeesalaryUserUpd(eid1,beforeSalary1);
        if (upd){
            int del = adjustsalaryService.getAdjustsalaryUserDel(eid1);
            return true;
        }else {
            return false;
        }
    }

    /**
     * 添加新的涨薪信息 postman测试完成
     * @param adjustsalary
     * @return
     */
    @PostMapping("/getAdjustsalaryUserAdd")
    public Boolean getAdjustsalaryUserAdd(@RequestBody Adjustsalary adjustsalary){
        boolean Add = adjustsalaryService.save(adjustsalary);
        System.out.println(adjustsalary);
        if (Add){
            int eid = adjustsalary.getEid();
            int monthSalary = adjustsalary.getAfterSalary();
            boolean upd2 = employeesalaryService.getemployeesalaryUserUpd(eid,monthSalary);
        }
        return Add;
    }

    /**
     *根据id修改涨薪信息  post测试完成
     * @param adjustsalary
     * @return
     */
    @PutMapping("/getAdjustsalaryUserUpd")
    public Boolean getAdjustsalaryUserUpd(@RequestBody Adjustsalary adjustsalary, Employeesalary employeesalary){
        boolean upd = adjustsalaryService.getAdjustsalaryUserUpd(adjustsalary);
        if (upd){
            int eid = adjustsalary.getEid();
            int monthSalary = adjustsalary.getAfterSalary();
            boolean upd2 = employeesalaryService.getemployeesalaryUserUpd(eid,monthSalary);
        }
        return upd;
    }
}

